package xj.graph2d.tree;

import java.awt.*;

import javax.swing.*;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.DefaultTreeCellRenderer;

import xj.util.gui.TreeNodeToolTips;

public class DocumentTreeCellRenderer 
  extends DefaultTreeCellRenderer {

  protected DocumentTreeCellIcons icons;

  public DocumentTreeCellRenderer(DocumentTreeCellIcons icons) {
    this.icons = icons; 
  }

  public Component getTreeCellRendererComponent(JTree tree, Object value,
						boolean selected, boolean expanded, 
						boolean leaf, int row,
						boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

    String stringValue = (value == null ? "" : value.toString()); 

    /* Set the text. */
    setText(stringValue);
    /* Tooltips used by the tree. */
    if (value instanceof TreeNodeToolTips) {
      TreeNodeToolTips tips = (TreeNodeToolTips) value;
      setToolTipText(tips.getTip());
    } else {
      setToolTipText(stringValue);
    }

    if (icons != null) { 
      setIcon(icons.getTreeCellIcon(value));
    } else {
      setIcon(null);
    }

    return this;
  }

}
